# 代码结果：   
    # ConcreteComponent: Performing operation
    # DecoratorA: Performing additional operation before
    # ConcreteComponent: Performing operation
    # DecoratorA: Performing additional operation after
    # DecoratorB: Performing additional operation before
    # DecoratorA: Performing additional operation before
    # ConcreteComponent: Performing operation
    # DecoratorA: Performing additional operation after
    # DecoratorB: Performing additional operation after


from abc import ABC, abstractmethod

# 定义组件接口
class Component(ABC):
    @abstractmethod
    def sample_operation(self):
        pass

# 具体组件实现
class ConcreteComponent(Component):
    def sample_operation(self):
        print("ConcreteComponent: Performing operation")

# 装饰器抽象类
class Decorator(ABC):
    def __init__(self, component: Component):
        self._component = component

    @abstractmethod
    def sample_operation(self):
        pass

# 具体装饰器 A
class ConcreteDecoratorA(Decorator):
    def __init__(self, component: Component):
        super().__init__(component)

    def sample_operation(self):
        print("DecoratorA: Performing additional operation before")
        self._component.sample_operation()
        print("DecoratorA: Performing additional operation after")

# 具体装饰器 B
class ConcreteDecoratorB(Decorator):
    def __init__(self, component: Component):
        super().__init__(component)

    def sample_operation(self):
        print("DecoratorB: Performing additional operation before")
        self._component.sample_operation()
        print("DecoratorB: Performing additional operation after")

# 客户端代码
if __name__ == "__main__":
    base_component = ConcreteComponent()
    decorated_component_a = ConcreteDecoratorA(base_component)
    decorated_component_b = ConcreteDecoratorB(decorated_component_a)

    base_component.sample_operation()
    decorated_component_a.sample_operation()
    decorated_component_b.sample_operation()